<template>
    <view style="padding: 10upx 20upx;">
        <view class="enter">
            <view class="enter_title">企业发布</view>
            <!-- 注意，如果需要兼容微信小程序，最好通过setRules方法设置rules规则 -->
            <u--form labelPosition="left" :model="model1" :rules="rules" ref="uForm" labelWidth="auto"
                :labelStyle="{ fontSize: '12px' }">
                <u-form-item label="发布名称" prop="user_name">
                    <u--input v-model="model1.user_name" border="none"></u--input>
                </u-form-item>
                <u-form-item label="发布标题" prop="user_title">
                    <u--input v-model="model1.user_title" border="none"></u--input>
                </u-form-item>
                <u-form-item label="联系电话" prop="user_phone">
                    <u--input v-model="model1.user_phone" border="none"></u--input>
                </u-form-item>
                </u-form-item>
                <u-form-item label="省市" prop="area_id">
                    <u--input v-model="model1.area_id" border="none"></u--input>
                </u-form-item>
                <u-form-item label="所属赛道" prop="saidao_id">
                    <u--input v-model="model1.saidao_id" border="none"></u--input>
                </u-form-item>
            </u--form>
        </view>
        <view class="custom">
            <u-button type="primary" shape="circle" @click="handleSubmit">提交</u-button>
        </view>

    </view>
</template>

<script>
import { onLoad } from '@dcloudio/uni-app';

export default {
    data() {
        return {
            showSex: false,
            model1: {
                user_name: '',
                user_title: '',
                user_phone: '',
                area_id: '',
                saidao_id: ''
            },
            rules: {
                'user_name': {
                    type: 'string',
                    required: true,
                    message: '请填写姓名',
                    trigger: ['blur', 'change']
                },
                'user_title': {
                    type: 'string',
                    max: 1,
                    required: true,
                    message: '请填写标题',
                    trigger: ['blur', 'change']
                },
                'user_phone': {
                    type: 'string',
                    max: 1,
                    required: true,
                    message: '请填写手机号',
                    trigger: ['blur', 'change']
                },
            },
            radio: '',
            switchVal: false,
            id:undefined
        };
    },
    methods: {
        async handleSubmit(e) {
            let res
            if(this.id){
                res = this.$api.operaModUserPublish({ ...this.model1,id:this.id })
                
            }else{
                res = this.$api.operaUserPublish({ ...this.model1 })
            }
            global.showToast('发布成功')
            uni.navigateBack({
                delta: 1,
            });
        },
    },
    onLoad() {
        //如果需要兼容微信小程序，并且校验规则中含有方法等，只能通过setRules方法设置规则。
        this.$refs.uForm.setRules(this.rules)
        const eventChannel = this.getOpenerEventChannel();
        eventChannel.on('acceptDataFromSourcePage',  (data) => {
            // console.log(data.param.user_name,'111'); // 输出: value1
            this.model1 = {
                user_name: data.param.user_name,
                user_title:  data.param.user_title,
                user_phone: data.param.user_phone,
                area_id: data.param.area_id,
                saidao_id:data.param.saidao_id,
            }
            this.id = data.param.id
        });
    },
};
</script>
<style scoped lang="scss">
.enter {
    background: #FFFFFF;
    box-shadow: 0px 6px 16px 0px rgba(0, 0, 0, 0.1);
    border-radius: 8upx;
    padding: 20upx;

    .enter_title {
        padding-bottom: 20upx;
        border-bottom: 1px solid #f0f0f0;
    }

    .enter_label {
        font-size: 20upx;
        margin-bottom: 10upx;
    }
}

.custom {
    margin-top: 20upx;
}
</style>
